package com.wva.common.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 * 日志切面：记录操作日志
 */
@Component
@Aspect
@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
public class LogRecordAspect {
    /**
     * 代理所有控制层方法的切入点
     */
    @Pointcut("execution(* com.wva.*.controller.*.*(..))")
    public void pt() {}

    /**
     * 控制层方法环绕通知
     */
    @Around("pt()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        Object[] args = joinPoint.getArgs();
        Object result;
        // log.info("{}() start", joinPoint.getSignature().getName());
        //记录入参到日志
        log.info("params={}", args);
        result = joinPoint.proceed(args);
        // log.info("{}() end, return={}", joinPoint.getSignature().getName(), result);
        return result;
    }
}